package config

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

type Config struct {
	WikiPath string `json:"wikipath"`
	WorkerCount int `json:"workercount"`
	Lines int `json:"lines"` // 限制读取的行数，如果为负数则读完
	DB DB `json:"db"`
}

type DB struct {
	Host     string `json:"host"`
	Username string `json:"username"`
	Password string `json:"password"`
	Port     int `json:"port"`
	DataBase string `json:"database"`
}

var Env = "dev"
var Conf Config

func init() {
	content, err := ioutil.ReadFile("./config.json")
	if err != nil {
		fmt.Println("read config json file error")
		panic(err)
	}
	err = json.Unmarshal(content, &Conf)
	if err != nil {
		fmt.Println("json parse error")
		panic(err)
	}
	fmt.Println("config", Conf)
}
